/*
package com.zzz.springbootdemo.elasticsearch.controller;

import com.zzz.springbootdemo.elasticsearch.dao.UserDao;
import com.zzz.springbootdemo.elasticsearch.vo.User;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/es")
public class ES {

    @Autowired
    private UserDao dao;

    @RequestMapping("/insert")
    public String insert(User user) {
        System.out.println(user.toString());
        String result = "seccessful";
        dao.save(user);
        return result;
    }

    @RequestMapping("search/{msg}")
    public Map<String,Object> search(@PathVariable String msg) {

        QueryBuilder queryBuilder = QueryBuilders.queryStringQuery(msg);
        Iterable<User> iterable = (Iterable<User>) queryBuilder.queryName(msg);
        Iterator<User> irerator = iterable.iterator();
        List<User> list=new ArrayList<User>();
        while(irerator.hasNext()){
            User user=irerator.next();
            System.out.println(user.toString());
            list.add(user);
        }
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("resutl",list);
        return map;
    }

}
*/
